package top.zuli.package01.class04;

public class BinarySearchArray {
    public static void main(String[] args) {
        int[] arr = {1,3,5,7,9,11,13};
        int target = 3;
        int head = 0;
        int end = arr.length-1;
        boolean tag = true;
        while (head<=end){
            int middle = (head + end)/2;
            if (arr[middle]==target){
                System.out.println("查找到元素："+target+"，小标："+middle);
                tag = false;
                break;
            }else if (arr[middle]>target){
                end = middle - 1;
            }else {
                head = middle + 1;
            }
        }
        if (tag){
            System.out.println("没有找到目标元素"+target);
        }
    }
}
